import java.util.*;

class MyStack {
    private int[] array;
    private int top;

    public MyStack() {
        this.array = new int[10];
        this.top = 0;
    }
    //把元素入栈
    public int push(int item) {
        if (this.array.length == this.top) {
            this.array = Arrays.copyOf(this.array,this.array.length*2);
        }
        this.array[top++] = item;
        return item;
    }
    //拿到栈顶元素
    public int  peek() {
        if (empty()) {
            throw new UnsupportedOperationException("栈为空！");
        }
        int ret = this.array[this.top-1];
        return ret;
    }
    //弹出栈顶元素
    public int pop() {
        if (empty()) {
            throw new UnsupportedOperationException("栈为空！");
        }
        int ret = this.array[top-1];
        this.top--;
        return ret;
    }
    //找栈里的元素
    public int search(int tmp) {
        if (empty()) {
            throw new UnsupportedOperationException("栈为空！");
        }
        for (int i = 0; i < this.top; i++) {
            if (this.array[i] == tmp) {
                return i;
            }
        }
        return -1;
    }
    //判断栈是否为空
    public boolean empty() {
        return this.top == 0;
    }
}
public class Test {
    public static void main(String[] args) {
        MyStack stack = new MyStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
    }
}